//利用多态画图的实现代码

//父类
class Shape{
    public void draw(){
        System.out.println("画图形");
    }
}

//多个子类、基类
class Rect extends Shape{
    //重写：1、方法名相同 2、参数列表相同 3、返回值相同
    @Override
    public void draw() {
        System.out.println("画矩形！");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("画圆形！");
    }
}
class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("画花！");
    }
}


public class Text {
    //有多态的情况
    public static void drawMap1(){
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();

        //在这其中发生了“向上转型”
        //父类型的数组，子类型的对象

        Shape[] shapes = {cycle,rect,cycle,rect,flower};

        for(Shape shape1 : shapes){
            shape1.draw();
        }
    }


    //没有多态的情况
    public static void drawMap2(){
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();
        String[] shapes = {"cycle", "rect", "cycle", "rect", "flower"};
        for (String s : shapes) {
            if (s.equals("cycle")) {
                cycle.draw();
            } else if (s.equals("rect")) {
                rect.draw();
            } else if (s.equals("flower")) {
                flower.draw();
            }
        }
    }

    public static void main(String[] args) {
        drawMap1();
        drawMap2();
    }
}
